#Appendix D- Alternative temporal windows

#Individual coincidence windows (Table D1)
#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0,sigtest="shuffle.surrogate")


#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3,sigtest="shuffle.surrogate")


#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7,sigtest="shuffle.surrogate")


#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11,sigtest="shuffle.surrogate")

#Gov battle deaths
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-130]
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12,sigtest="shuffle.surrogate")


#Table D2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12, sigtest="shuffle.surrogate")


#Table D3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=0, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=1, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=2, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=3, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=4, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=5, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=6, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=7, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=8, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=9, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=10, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=11, sigtest="shuffle.surrogate")


set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12,sigtest="shuffle.surrogate")

set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 0, tau=12, sigtest="shuffle.surrogate")


#Table D4
#2-month temporal windows 

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
countries<-countries[-129]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")



#Spillover
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")


#Table D5
#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-131]
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")



#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-131]
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")



#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")



#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=3, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=5, sigtest="shuffle.surrogate")

#CW 4
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=7, sigtest="shuffle.surrogate")

#CW 5
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=9, sigtest="shuffle.surrogate")

#CW 6
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 2, tau=11, sigtest="shuffle.surrogate")















